#ifndef TEXTMININGAPP_HH_
# define TEXTMININGAPP_HH_

///
/// \file TextMiningApp.hh
/// \brief The main file of the TextMiningApp exe.
/// \author Coddy Levi, Sylvain Lobry
/// \version 1.0
///


#include "optimized_trie.hh"

#include <iostream>

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/mman.h>
#include <fcntl.h>

#include <stdlib.h>

#include <string.h>
#include <list>
#include <string>



///
/// \brief Structure that holds the information about a match.
///
typedef struct
{
  std::string	word;
  unsigned	frequency;
  unsigned	d;
} t_match;

///
/// \brief The list of matches we found.
///
typedef std::list<t_match>	t_result_list;


///
/// \brief Data in order to optimize search algorithm
///
typedef struct
{
  t_result_list result;
  t_match** marks;
  OptimizedTrie* ot_head;
  unsigned nb_node_visited;
} t_data;




///
/// \brief Compare function used by sort. It compares 2 matches and give them
///  in the order they should be print onto the screen.
///
/// \param[in] item1 The first item.
/// \param[in] item2 The second item.
/// \return True if item1 > item2, false otherwise.
///
bool compare (const t_match& item1,
	      const t_match& item2);

///
/// \brief display results onto std::cout in the expected format.
///
/// \param[in] result The list of result.
/// \param[in] d The maximum distance to be searched.
///
void display_result(t_result_list& result, int d);

///
/// \brief The main algorithm, the one that gives the list of result.
///
/// \param[in] ot The Trie we search in
/// \param[in] word The original word
/// \param[in] d The remaining distance to be searched.
/// \param[in] data The data, including the resulting list.
/// \param[in] guess The current guess.
///
void closest_match(const OptimizedTrie* ot,
		   const char* word,
		   int d,
		   t_data* data,
		   std::string guess = std::string());

///
/// \brief main function.
///
/// \param[in] argc The number of arguments.
/// \param[in] argv The arguments.
///
/// \return 0 if everything is right, 1 otherwise.
///
int main(int argc,
	 char* argv[]);

#endif /* !TEXTMININGAPP_HH_ */
